using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class MasterPageItem : UserControl
	{
		private const string TAG = "MasterPageItem";
		private MasterPageTitleCtrl titleCtrl;
		private MasterPageGroupItem imgGroupCtrl;
		public static DependencyProperty ListItemProperty = DependencyProperty.Register("ItemObject", typeof(MasterImgGroup), typeof(MasterPageItem), new PropertyMetadata(null, new PropertyChangedCallback(MasterPageItem.OnItemPropertyChanged)));
		internal Grid LayoutRoot;
		private bool _contentLoaded;
		public MasterImgGroup ItemObject
		{
			get
			{
				return (MasterImgGroup)base.GetValue(MasterPageItem.ListItemProperty);
			}
			set
			{
				base.SetValue(MasterPageItem.ListItemProperty, value);
			}
		}
		public MasterPageItem()
		{
			this.InitializeComponent();
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == MasterPageItem.ListItemProperty)
			{
				(dependencyObject_0 as MasterPageItem).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				this.RefreshItem(dependencyPropertyChangedEventArgs_0.get_NewValue() as MasterImgGroup);
			}
			catch (Exception ex)
			{
				Log.smethod_1(base.GetType().get_Name(), ex.get_StackTrace());
			}
		}
		private void RefreshItem(MasterImgGroup item)
		{
			if (item == null)
			{
				return;
			}
			this.titleCtrl = (MasterPageTitleCtrl)UIElementTraveler.FindElementRecursive(this, typeof(MasterPageTitleCtrl));
			this.imgGroupCtrl = (MasterPageGroupItem)UIElementTraveler.FindElementRecursive(this, typeof(MasterPageGroupItem));
			if (item.groupName == "AuthorTitle")
			{
				if (this.titleCtrl == null)
				{
					this.LayoutRoot.get_Children().Clear();
					this.titleCtrl = new MasterPageTitleCtrl();
					BasePage rootPage = ToolFunction.GetRootPage();
					if (rootPage is BackgroundMasterPage)
					{
						BackgroundMasterPage backgroundMasterPage = rootPage as BackgroundMasterPage;
						if (backgroundMasterPage.masterAlbum != null)
						{
							this.titleCtrl.SetContent(backgroundMasterPage.masterAlbum.authorDescription, backgroundMasterPage.masterAlbum.authorQuote);
						}
						this.LayoutRoot.get_Children().Add(this.titleCtrl);
						return;
					}
				}
			}
			else
			{
				if (this.imgGroupCtrl == null)
				{
					this.LayoutRoot.get_Children().Clear();
					this.imgGroupCtrl = new MasterPageGroupItem();
					this.LayoutRoot.get_Children().Add(this.imgGroupCtrl);
				}
				this.imgGroupCtrl.SetContent(item);
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/AlbumCover/MasterPageItem.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
		}
	}
}
